﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using SARS.Biz;
using SARS.Biz.Facades;
using SARS.Entity;

namespace SARS.Tutor
{
    public partial class StudentAttendance : Page
    {
        private readonly ICourseBO _courseBO = new CourseBO();
        private readonly ISessionBO _sessionBO = new SessionBO();
        private readonly IUserBO _userBO = new UserBO();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Roles"] != null && (RoleType.Tutor == (RoleType)Session["Roles"] || RoleType.Lecturer == (RoleType)Session["Roles"]))
            {
                
                if (!IsPostBack)
                {
                }
            }
            else
            {
                Response.Write("<script language='javascript'>window.alert('Your role is not allow to access this page.');" +
                               "window.location='../Account/Login.aspx';</script>");

            }
            
        }

        protected void ddlSession_SelectedIndexChanged(object sender, EventArgs e)
        {
        }

        protected void btnAddSession_Click(object sender, EventArgs e)
        {
            Response.Redirect("AddSession.aspx");
        }

        protected void ucProgramCourse_OnSelectedCourseChanged()
        {
            ddlSession.DataSource = RetrieveAllSessionById(UcProgramCourse.SelectedCourseValue);
            ddlSession.DataBind();

            ddlSession.Items.Insert(0, "- Please select the Session -");
        }

        private List<SessionEntity> RetrieveAllSessionById(int id)
        {
            return _sessionBO.RetrieveSessionByCourseId(id);
        }


        protected void btnAssign_Click(object sender, EventArgs e)
        {
            if (UcProgramCourse.SelectedProgramValue > 0 && UcProgramCourse.SelectedCourseValue > 0 &&
                Convert.ToInt32(ddlSession.SelectedValue) > 0)
            {
                Response.Redirect(string.Format("CheckStudentAttendance.aspx?pid={0}&cid={1}&sid={2}",
                    UcProgramCourse.SelectedProgramValue, UcProgramCourse.SelectedCourseValue, ddlSession.SelectedValue));
            }
            else
            {
                Response.Write("<script>alert('Please select all information!')</script>");
            }
        }

        protected void grvStudents_DataBound(object sender, EventArgs e)
        {
        }


        protected void grvStudents_RowDataBound(object sender, GridViewRowEventArgs e)
        {
        }

        protected void btnEditAttendance_Click(object sender, EventArgs e)
        {
            Response.Redirect(string.Format("EditStudentAttendance.aspx?pid={0}&cid={1}&sid={2}",
                UcProgramCourse.SelectedProgramValue, UcProgramCourse.SelectedCourseValue, ddlSession.SelectedValue));
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Default.aspx");
        }
    }
}